package Underworld_Survival;

import java.util.*;

public abstract class Shoe extends Equipment {
    protected transient String shoeEffectId;//应用该鞋子时唯一效果id
    protected transient Map<AttributeType,EffectValue> onEquip;//应用鞋子时的具体效果
    protected transient Map<AttributeType, EffectValue> reverse;//移除鞋子时的效果
    protected transient EffectManager manager;//记录鞋子效果，用于正确移除
    protected transient EquipmentEffect effect;//防具普通的加成

    public Shoe(EffectManager manager) {this.manager = manager;}
    public Shoe(EffectManager manager, EquipmentEffect effect){
        this.manager = manager;
        this.effect = effect;}
    public Shoe(String name, String introduction, String itemEffect, CurrencyType purchaseCurrency,
                 int priceOfPurchase, int priceOfSelling, Map<AttributeType, EffectValue> onEquipEffect){
        super(name,introduction,itemEffect,purchaseCurrency,priceOfPurchase,priceOfSelling);
        this.onEquip=new HashMap<>(onEquipEffect);// 复制传入的效果数据
        shoeEffectId=UUID.randomUUID().toString();
        this.reverse=new HashMap<>();
        this.effect=new EquipmentEffect(
                role -> {equip(role);},
                role -> {unequip(role);}
        );
    }

    public void equip(Role role) {
        // 注册效果并自动绑定到装备实例
        this.manager=role.getEffectManager();
        String effectId = manager.applyEffect(shoeEffectId, onEquip);
        Map<AttributeType, Float> actualValues = manager.getEffectsById(effectId,role);
        role.modifyAttributes(actualValues,true);
    }
    public void unequip(Role role) {
        Map<AttributeType, Float> reverse = manager.removeEffects(shoeEffectId,role);
        role.modifyAttributes(reverse,false);
    }

    public Map<AttributeType,EffectValue> getOnEquip(){
        return onEquip;
    }

}

//<草鞋>strawSandals
class strawSandals extends Shoe{
    public strawSandals() {
        super("<草鞋>", "别嫌弃，总比没有好吧？",
                "速度+4", CurrencyType.GOLD, 100, 50,
                // 直接传入预定义的效果数据
                Map.of(AttributeType.BONUS_EP, new FixedValue(4f))
        );
        shoeEffectId="草鞋"+shoeEffectId;
    }


    @Override
    public String getItemId() { return "shoe_strawSandals"; }

}
//<运动鞋>sportsShoes
class sportsShoes extends Shoe{
    public sportsShoes () {
        super("<运动鞋>", "现代很多人穿的鞋子，舒适而美观",
                "速度+8", CurrencyType.GOLD, 200, 100,
                // 直接传入预定义的效果数据
                Map.of(AttributeType.BONUS_EP, new FixedValue(8f))
        );
        shoeEffectId="运动鞋"+shoeEffectId;
    }

    @Override
    public String getItemId() { return "shoe_sportsShoes"; }

}
//<迅影鞋>swiftShadowShoes
class swiftShadowShoes extends Shoe{
    public swiftShadowShoes () {
        super("<迅影鞋>", "传说中，迅影鞋由上古速度之神的羽毛与神秘星核锻造而成",
                "速度+15", CurrencyType.DIAMOND, 90, 180,
                // 直接传入预定义的效果数据
                Map.of(AttributeType.BONUS_EP, new FixedValue(15f))
        );
        addSpecialEffect(new preemptEffect(1f));
        shoeEffectId="迅影鞋"+shoeEffectId;
    }

    @Override
    public String getItemId() { return "shoe_swiftShadowShoes"; }

}
//<魔法靴>magicalBoots
class magicalBoots extends Shoe{
    public magicalBoots () {
        super("<魔法靴>", "束缚与自由的临界点，藏在魔法编织的纹路里",
                "速度提升30% 力量、防御提升、暴击率、暴击效果提升10%", CurrencyType.DIAMOND, 70, 140,
                // 直接传入预定义的效果数据
                Map.of(AttributeType.BONUS_EP, new DynamicValue(ctx -> ctx.getBaseEP()*0.3f),AttributeType.BONUS_STR, new DynamicValue(ctx -> ctx.getBaseStr()*0.1f),
                        AttributeType.BONUS_DEF, new DynamicValue(ctx -> ctx.getBaseDef()*0.1f),AttributeType.BONUS_CRITRATE, new DynamicValue(ctx -> ctx.getBaseCritRate()*0.1f)
                ,AttributeType.BONUS_CRITMULTIPLIER, new DynamicValue(ctx -> ctx.getBaseCritMultiplier()*0.1f))
        );
        shoeEffectId="魔法靴"+shoeEffectId;
    }

    @Override
    public String getItemId() { return "shoe_magicalBoots"; }

}
